﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DigitalAmele.BLL.Adapters;
using Bxas.Core.Exceptions;

namespace DigitalAmele.BLL.Authantication
{
    public class MembersBs : DigitalAmele.BLL.Abstracts._MembersBs
    {
        public string get_fullname(Members m)
        {
            if (string.IsNullOrEmpty(m.FirstName) && string.IsNullOrEmpty(m.LastName)) return string.Empty;

            return m.FirstName + (string.IsNullOrEmpty(m.MiddleName) ? "" : (" " + m.MiddleName)) + " " + m.LastName;
        }

        public bool get_for_login(string userNameOrEMail, string password, ref Members Member)
        {
            System.Data.SqlClient.SqlCommand sqlcommand = new System.Data.SqlClient.SqlCommand();
            sqlcommand.CommandText = SqlStrrings.MemberSqlStrings.LoginSql;

            sqlcommand.Parameters.AddWithValue(Members.ColumnNames.Password, password);
            sqlcommand.Parameters.AddWithValue(Members.ColumnNames.Email, userNameOrEMail);
            sqlcommand.Parameters.AddWithValue(Members.ColumnNames.UserName, userNameOrEMail);
            try
            {
                List<Members> list = get(sqlcommand);
                Member = list.First<Members>();
                if (list == null) return false;
                return list.Count == 1;
            }
            catch (Exception ex)
            {
                throw ErrorLogInsert(ex);
            }


        }

        public bool get_for_UserNameControl(string userName)
        {
            System.Data.SqlClient.SqlCommand sqlcommand = new System.Data.SqlClient.SqlCommand();
            sqlcommand.CommandText = SqlStrrings.MemberSqlStrings.UserNameControlSql;
            sqlcommand.Parameters.AddWithValue(Members.ColumnNames.UserName, userName);
            try
            {
                List<Members> list = get(sqlcommand);

                if (list == null) return false;
                return list.Count > 0;
            }
            catch (Exception ex)
            {
                throw ErrorLogInsert(ex);
            }

        }

    }
}